﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace POS
{
    public static class Table
    {
        public static List<Order> orderList = new List<Order>();

        public static UIElement Render()
        {
            var list = new ListBox();
            foreach (var order in orderList)
            {
                var renderedTodoItem = order.Render();

                var listTodoItemItem = new ListBoxItem();
                listTodoItemItem.Content = renderedTodoItem;
                var deleteButtons = (renderedTodoItem as Panel).Children.OfType<Button>();
                foreach (var delButton in deleteButtons)
                {
                    delButton.Click += (snd, args) =>
                    {
                        orderList.Remove(order);
                    };
                }

                list.Items.Add(listTodoItemItem);
            }

            double totalPrice = 0;

            foreach (var order in Table.orderList)
            {
                totalPrice += order.Price;
            }

            var textTextBox = new TextBlock();
            textTextBox.Text = String.Format("Total price: {0} $", totalPrice.ToString());
            textTextBox.FontWeight = FontWeights.Bold;
            textTextBox.FontSize = 11;   
            list.Items.Add(textTextBox);

            return list;
        }     
    }
}
